package com.example.basics.controller;

import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RDelayedQueue;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

@RestController
@Slf4j
public class SimpleDelayQueueController {

    @Resource(name = "rDelayedQueue")
    private RDelayedQueue<String> rDelayedQueue;

    @GetMapping("/offer")
    public void offer() {
        for (int i = 1; i <= 2; i++) {
            rDelayedQueue.offer("task: " + i, 30, TimeUnit.SECONDS);
            log.info("添加到队列的消息：" + "task" + i);
        }
    }
}
